#!/system/bin/sh
PREFIX=$(realpath $(cd "$(dirname "$0")"; pwd))

cd $PREFIX

busybox mount -t ext4 -o loop ubuntu.ext4 ubuntu

mount --bind /dev ubuntu/dev
mount --bind /proc ubuntu/proc
mount --bind /sys ubuntu/sys

mkdir -p ubuntu/tmp
mount --bind /data/local/tmp ubuntu/tmp
chmod 777 ubuntu/tmp

mkdir -p ubuntu/mnt
mount --bind /mnt ubuntu/mnt

mkdir -p ubuntu/data
mount --bind /data ubuntu/data

chroot ubuntu /bin/bash -x <<'EOF'
su -
umount /dev/pts
mount devpts /dev/pts -t devpts
/etc/init.d/ssh start
exit
EOF
